package com.light.mytext.lock

import android.util.Log

class SynchronizedDemo : Runnable {
    //共享资源
    var i = 0

    /**
     * synchronized 修饰实例方法
     */
    @Synchronized
    fun increase() {
        i++
        Log.i("Lock==", "increase==$i")
    }

    override fun run() {
        for (j in 0..9999) {
            increase()
        }
    }

    fun main() {
        val test = SynchronizedDemo()
        val t1 = Thread(test)
        val t2 = Thread(test)
        t1.start()
        t2.start()
        t1.join()
        t2.join()
    }


}